package J20250227_dfs;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description: 发现环——https://www.lanqiao.cn/problems/108/learning/?page=1&first_category_id=1&tags=DFS&tag_relation=intersection
 * User: 王圆豪
 * Date: 2025-03-12
 * Time: 0:31
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        HashMap<Integer, List<Integer>> map = new HashMap<>();
        int[] from = new int[N+1];
        for(int i = 0; i < N; i++){
            int a = scan.nextInt();
            int b = scan.nextInt();
            if(!map.containsKey(a)) map.put(a,new ArrayList<>());
            if(!map.containsKey(b)) map.put(b,new ArrayList<>());
            map.get(a).add(b);
            map.get(b).add(a);
            from[a]++;
            from[b]++;
        }
        Queue<Integer> q = new LinkedList<>();
        for(int i = 1; i <= N; i++){
            if(from[i] == 1) q.add(i);
        }
        while(!q.isEmpty()){
            int tmp = q.poll();
            for(int a : map.get(tmp)){
                from[a]--;
                if(from[a]==1)q.add(a);
            }
        }
        List<Integer> ret = new LinkedList<>();
        for(int i = 1; i <= N; i++){
            if(from[i]==2) ret.add(i);
        }
        Collections.sort(ret);
        for(int a : ret)
            System.out.print(a + " ");
        scan.close();
    }
}
